#include <stdio.h>
#include <math.h>

int isPrime(int n)
{
	if (n==2 || n==3 || n==5 || n==7)return 1;
	if (n%2 == 0 || n%3 == 0)return 0;
	int i;
	for (i=5; i<=floor(sqrt(n)); i+=6) {
		if (n%i == 0)return 0;
		if (n%(i+2) == 0)return 0;
	}
	return 1;
}

int main()
{
	unsigned long d = 2, c = 1, n;
	for (d=999; d>=2; d-=2) {
		if (isPrime(d)) {
			c = 1;
			n = 10;
			while ((n-1) % d != 0) {
				c++;
				n *=10; 
			}
			printf("%ld ", c);
			if (d == 1+c){printf("%ld\n", d);return;}
		}
	}
	printf("%ld %d\n", d, isPrime(997));
}
